﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MS.Basic.WriteAPI.Controllers
{
    /// <summary>
    /// 写API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AccountWriteController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"> 中介者</param>
        public AccountWriteController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加图片
        /// </summary>
        /// <param name="file"> 图片文件</param>
        /// <returns> 图片URL</returns>
        [HttpPost]
        public IActionResult AddImage(IFormFile file)
        {
            var fileName=file.FileName;
            var path=Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", fileName);
            using (var fs = new FileStream(path, FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            var url="/Images/"+ fileName;
            return Ok(url);
        }
    }
}
